<<<<<<< HEAD
<template>
  <div class="manage">
    <el-dialog
      :visible.sync="isShow"
      :title="operateType === 'add' ? '新增商品' : '更新商品'"
    >
      <CommonForm :formLabel="operateFromLabel" :form="operateFrom">
      </CommonForm>
      <div slot="footer" class="dialog-footer">
        <el-button @click="isShow = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
    <div class="header">
      <el-button type="primary" icon="el-icon-circle-plus"> 新增</el-button>
      <CommonForm inline :formLabel="formLabel" :form="searchForm">
        <el-button type="primary" icon="el-icon-search"> 搜索</el-button>
      </CommonForm>
    </div>
    <CommonTable
      :tableData="tableData"
      :tableLabel="tableLabel"
      :config="config"
      @changePage="findPage"
      @edit="editProduct"
      @del="delProduct"
    ></CommonTable>
  </div>
</template>

<script>
import CommonForm from "@/components/common/Form.vue";
import CommonTable from "@/components/common/Table.vue";
export default {
  components: {
    CommonForm,
    CommonTable
  },
  data() {
    return {
      isShow: false,
      operateType: "add",
      operateFrom: {
        name: ""
      },
      operateFromLabel: [
        {
          model: "name",
          label: "商品名"
        },
        {
          model: "code",
          label: "编号"
        },
        {
          model: "num",
          label: "数量"
        },
        {
          model: "price",
          label: "价格"
        }
      ],
      searchForm: {
        keyword: ""
      },
      formLabel: [
        {
          model: "keyword",
          label: "商品名称"
        }
      ],
      tableData: [],
      tableLabel: [
        { prop: "id", label: "ID" },
        {
          prop: "name",
          label: "商品名"
        },
        {
          prop: "code",
          label: "编号"
        },
        {
          prop: "num",
          label: "数量"
        },
        {
          prop: "price",
          label: "价格"
        }
      ],
      config: {
        currentPage: 1,
        pageSize: 7,
        total: 2,
        loading: false,
        control: true
      }
    };
  },
  methods: {
    //无误获取参数
    findPage: function() {
      let pageRequest = {
        pageNumber: this.config.currentPage,
        pageSize: this.config.pageSize
      };
      this.config.loading = true;
      this.$http.product
        .findPage(pageRequest)
        .then(res => {
          this.tableData = res.content;
          this.config.total = res.totalElements;
          this.config.loading = false;
        })
        .catch(error => {
          console.log(error);
        });
    },
    editProduct(row) {
      this.operateType = "edit";
      this.isShow = true;
      this.operateFrom = row;
    },
    confirm() {
      if (this.operateType === "edit") {
        this.$http.product.update(this.operateFrom).then(res => {
          console.log(res);
          this.isShow = false;
          this.findPage(); //编辑成功后需要重新刷新用户信息
        });
      }
    },
    delProduct(row) {
      this.$confirm("此操作将永久删除该商品, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http.product.delProduct(row.id).then(res => {
            console.log(res);
            this.$message({
              type: "success",
              message: "删除成功!"
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  },

  created() {
    //创建将数据请求发出
    this.findPage();
  }
};
</script>

<style lang="scss" scoped>
@import "~@/styles/manage.scss";
</style>
=======
<template>
  <div class="manage">
    <el-dialog
      :visible.sync="isShow"
      :title="operateType === 'add' ? '新增商品' : '更新商品'"
    >
      <CommonForm :formLabel="operateFromLabel" :form="operateFrom">
      </CommonForm>
      <div slot="footer" class="dialog-footer">
        <el-button @click="isShow = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
    <div class="header">
      <el-button type="primary" icon="el-icon-circle-plus"> 新增</el-button>
      <CommonForm inline :formLabel="formLabel" :form="searchForm">
        <el-button type="primary" icon="el-icon-search"> 搜索</el-button>
      </CommonForm>
    </div>
    <CommonTable
      :tableData="tableData"
      :tableLabel="tableLabel"
      :config="config"
      @changePage="findPage"
      @edit="editProduct"
      @del="delProduct"
    ></CommonTable>
  </div>
</template>

<script>
import CommonForm from "@/components/common/Form.vue";
import CommonTable from "@/components/common/Table.vue";
export default {
  components: {
    CommonForm,
    CommonTable
  },
  data() {
    return {
      isShow: false,
      operateType: "add",
      operateFrom: {
        name: ""
      },
      operateFromLabel: [
        {
          model: "name",
          label: "商品名"
        },
        {
          model: "code",
          label: "编号"
        },
        {
          model: "num",
          label: "数量"
        },
        {
          model: "price",
          label: "价格"
        }
      ],
      searchForm: {
        keyword: ""
      },
      formLabel: [
        {
          model: "keyword",
          label: "商品名称"
        }
      ],
      tableData: [],
      tableLabel: [
        { prop: "id", label: "ID" },
        {
          prop: "name",
          label: "商品名"
        },
        {
          prop: "code",
          label: "编号"
        },
        {
          prop: "num",
          label: "数量"
        },
        {
          prop: "price",
          label: "价格"
        }
      ],
      config: {
        currentPage: 1,
        pageSize: 7,
        total: 2,
        loading: false,
        control: true
      }
    };
  },
  methods: {
    //无误获取参数
    findPage: function() {
      let pageRequest = {
        pageNumber: this.config.currentPage,
        pageSize: this.config.pageSize
      };
      this.config.loading = true;
      this.$http.product
        .findPage(pageRequest)
        .then(res => {
          this.tableData = res.content;
          this.config.total = res.totalElements;
          this.config.loading = false;
        })
        .catch(error => {
          console.log(error);
        });
    },
    editProduct(row) {
      this.operateType = "edit";
      this.isShow = true;
      this.operateFrom = row;
    },
    confirm() {
      if (this.operateType === "edit") {
        this.$http.product.update(this.operateFrom).then(res => {
          console.log(res);
          this.isShow = false;
          this.findPage(); //编辑成功后需要重新刷新用户信息
        });
      }
    },
    delProduct(row) {
      this.$confirm("此操作将永久删除该商品, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http.product.delProduct(row.id).then(res => {
            console.log(res);
            this.$message({
              type: "success",
              message: "删除成功!"
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  },

  created() {
    //创建将数据请求发出
    this.findPage();
  }
};
</script>

<style lang="scss" scoped>
@import "~@/styles/manage.scss";
</style>
>>>>>>> origin/master
